const BASEURL = "http://192.168.31.209:9090/human/";

const request = ({
	method,
	url,
	param
}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url,
			method: method,
			data: param,
			header: {
				"Authorization": uni.getStorageSync("token") || ''
			},
			success: (res) => {
				let {
					data,
					data: {
						code,
						msg
					}
				} = res;
				console.log(res)
				if (code == 200) {
					resolve(data);
				} else if (code == 401) {
					uni.showModal({
						title: "提示",
						content: "当前用户未授权登陆，请前往授权页进行登陆",
						success: function(res) {
							if (res.confirm) {
								uni.reLaunch({
									url: '/pages/authorization/index'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				} else {
					uni.showToast({
						title: msg,
						icon: "none",
						mask: true
					})
				}
			},
			fail: (error) => {
				reject();
			}
		})
	})
}
export function $post(url, param) {
	return request({
		method: 'POST',
		url,
		param
	})
}
export function $get(url, param) {
	return request({
		method: 'GET',
		url,
		param
	})
}
